
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N = 2e5 + 10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
ll n, m, p, x, last;
ll t[15], w[10005], v[10005], f[10005];
ll val[] = {0, 9, 7, 8, 5, 6, 3, 4, 2};
int main()
{
    cin >> n >> m;
    for(ll i = 1; i <= n; i++)
    {
        cin >> p >> x;
        t[p] += x;
    }
    for(ll i = 1; i <= 8; i++)
    {
        for(ll j = 1; j <= t[i] / 64; j++)
            for(ll k = m; k >= 1; k--)
                f[k] = max(f[k], f[k - 1] + val[i] * 64);
        last = t[i] % 64;
        if(last)
            for(ll k = m; k >= 1; k--)
                f[k] = max(f[k], f[k - 1] + val[i] * last);
    }
    cout << f[m];
}
